home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / WPrefs.app / TexturePanel.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-14  |  43.4 KB  |  1,657 lines

  1. /* TexturePanel.c- texture editting panel
  2.  * 
  3.  *  WPrefs - WindowMaker Preferences Program
  4.  * 
  5.  *  Copyright (c) 1998, 1999 Alfredo K. Kojima
  6.  *  Copyright (c) 1998 James Thompson
  7.  * 
  8.  *  This program is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2 of the License, or
  11.  *  (at your option) any later version.
  12.  *
  13.  *  This program is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with this program; if not, write to the Free Software
  20.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  21.  *  USA.
  22.  *
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <ctype.h>
  30.  
  31. #include <X11/Xlib.h>
  32.  
  33.  
  34. #include <WINGs.h>
  35. #include <WUtil.h>
  36.  
  37. #include "WPrefs.h"
  38.  
  39. #include "TexturePanel.h"
  40.  
  41.  
  42. #define MAX_SECTION_PARTS 5
  43.  
  44. typedef struct _TexturePanel {
  45.     WMWindow *win;
  46.  
  47.     /* texture name */
  48.     WMFrame *nameF;
  49.     WMTextField *nameT;
  50.     
  51.     /* texture type */
  52.     WMPopUpButton *typeP;
  53.  
  54.     /* default color */
  55.     WMFrame *defcF;
  56.     WMColorWell *defcW;
  57.  
  58.     WMFont *listFont;
  59.  
  60.     /*-- Gradient --*/
  61.  
  62.     Pixmap gimage;
  63.  
  64.     /* colors */
  65.     WMFrame *gcolF;
  66.     WMList *gcolL;
  67.     WMButton *gcolaB;
  68.     WMButton *gcoldB;
  69.     WMSlider *ghueS;
  70.     WMSlider *gsatS;
  71.     WMSlider *gvalS;
  72.  
  73.     WMSlider *gbriS;
  74.     WMSlider *gconS;
  75.  
  76.     /* direction (common) */
  77.     WMFrame *dirF;
  78.     WMButton *dirhB;
  79.     WMButton *dirvB;
  80.     WMButton *dirdB;
  81.  
  82.     /*-- Simple Gradient --*/
  83.  
  84.  
  85.     /*-- Textured Gradient --*/
  86.  
  87.     WMFrame *tcolF;
  88.     WMColorWell *tcol1W;
  89.     WMColorWell *tcol2W;
  90.  
  91.     WMFrame *topaF;
  92.     WMSlider *topaS;
  93.  
  94.     /*-- Image --*/
  95.     WMFrame *imageF;
  96.     WMScrollView *imageV;
  97.     WMTextField *imageT;
  98.     WMLabel *imageL;
  99.     WMButton *browB;
  100.     WMButton *dispB;
  101.     WMPopUpButton *arrP;
  102.  
  103.     RImage *image;
  104.     char *imageFile;
  105.  
  106.     /*****/
  107.  
  108.     WMButton *okB;
  109.     WMButton *cancelB;
  110.     
  111.     
  112.     WMCallback *okAction;
  113.     void *okData;
  114.     
  115.     WMCallback *cancelAction;
  116.     void *cancelData;
  117.  
  118.     /****/
  119.     WMWidget *sectionParts[5][MAX_SECTION_PARTS];
  120.  
  121.     int currentType;
  122.  
  123.     
  124.     proplist_t pathList;
  125.  
  126. } _TexturePanel;
  127.  
  128.  
  129.  
  130. #define TYPE_SOLID    0
  131. #define TYPE_GRADIENT    1
  132. #define TYPE_SGRADIENT    2
  133. #define TYPE_TGRADIENT    3
  134. #define TYPE_PIXMAP    4
  135.  
  136.  
  137. #define PTYPE_TILE    0
  138. #define PTYPE_SCALE    1
  139. #define PTYPE_CENTER    2
  140. #define PTYPE_MAXIMIZE    3
  141.  
  142.  
  143.  
  144. /*
  145.  *--------------------------------------------------------------------------
  146.  * Private Functions
  147.  *--------------------------------------------------------------------------
  148.  */
  149.  
  150. /************/
  151.  
  152. static void
  153. updateGradButtons(TexturePanel *panel)
  154. {
  155.     RImage *image;
  156.     WMPixmap *pixmap;
  157.     int colorn;
  158.     RColor **colors;
  159.  
  160.     colorn = WMGetListNumberOfRows(panel->gcolL);
  161.     if (colorn < 1) {
  162.     pixmap = NULL;
  163.     } else {
  164.     int i;
  165.     WMListItem *item;
  166.  
  167.     colors = wmalloc(sizeof(RColor*)*(colorn+1));
  168.  
  169.     for (i = 0; i < colorn; i++) {
  170.         item = WMGetListItem(panel->gcolL, i);
  171.         colors[i] = (RColor*)item->clientData;
  172.     }
  173.     colors[i] = NULL;
  174.  
  175.     image = RRenderMultiGradient(80, 30, colors, RHorizontalGradient);
  176.     pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
  177.                       image, 128);
  178.     RDestroyImage(image);
  179.     WMSetButtonImage(panel->dirhB, pixmap);
  180.     WMReleasePixmap(pixmap);
  181.  
  182.     image = RRenderMultiGradient(80, 30, colors, RVerticalGradient);
  183.     pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
  184.                       image, 128);
  185.     RDestroyImage(image);
  186.     WMSetButtonImage(panel->dirvB, pixmap);
  187.     WMReleasePixmap(pixmap);
  188.  
  189.     image = RRenderMultiGradient(80, 30, colors, RDiagonalGradient);
  190.     pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
  191.                       image, 128);
  192.     RDestroyImage(image);
  193.     WMSetButtonImage(panel->dirdB, pixmap);
  194.     WMReleasePixmap(pixmap);
  195.  
  196.     free(colors);
  197.     }
  198. }
  199.  
  200.  
  201.  
  202. static void
  203. updateTGradImage(TexturePanel *panel)
  204. {
  205.     RImage *image, *gradient;
  206.     WMPixmap *pixmap;
  207.     RColor from;
  208.     RColor to;
  209.     WMColor *color;
  210.  
  211.     if (!panel->image)
  212.     return;
  213.     
  214.     color = WMGetColorWellColor(panel->tcol1W);
  215.     from.red = WMRedComponentOfColor(color)>>8;
  216.     from.green = WMGreenComponentOfColor(color)>>8;
  217.     from.blue = WMBlueComponentOfColor(color)>>8;
  218.  
  219.     color = WMGetColorWellColor(panel->tcol2W);
  220.     to.red = WMRedComponentOfColor(color)>>8;
  221.     to.green = WMGreenComponentOfColor(color)>>8;
  222.     to.blue = WMBlueComponentOfColor(color)>>8;
  223.  
  224.     if (panel->image->width < 141 || panel->image->height < 91) {
  225.     image = RMakeTiledImage(panel->image, 141, 91);
  226.     } else {
  227.     image = RCloneImage(panel->image);
  228.     }
  229.  
  230.     if (WMGetButtonSelected(panel->dirhB)) {
  231.     gradient = RRenderGradient(image->width, image->height, &from, &to,
  232.                    RHorizontalGradient);
  233.     } else if (WMGetButtonSelected(panel->dirvB)) {
  234.     gradient = RRenderGradient(image->width, image->height, &from, &to,
  235.                    RVerticalGradient);
  236.     } else {
  237.     gradient = RRenderGradient(image->width, image->height, &from, &to,
  238.                    RDiagonalGradient);
  239.     }
  240.  
  241.     RCombineImagesWithOpaqueness(image, gradient,
  242.                  WMGetSliderValue(panel->topaS));
  243.     RDestroyImage(gradient);
  244.     pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->win),
  245.                       image, 128);
  246.  
  247.     WMSetLabelImage(panel->imageL, pixmap);
  248.     WMReleasePixmap(pixmap);
  249.     WMResizeWidget(panel->imageL, image->width, image->height);
  250.     RDestroyImage(image);
  251. }
  252.  
  253.  
  254. static void
  255. updateSGradButtons(TexturePanel *panel)
  256. {
  257.     RImage *image;
  258.     WMPixmap *pixmap;
  259.     RColor from;
  260.     RColor to;
  261.     WMColor *color;
  262.  
  263.     color = WMGetColorWellColor(panel->tcol1W);
  264.     from.red = WMRedComponentOfColor(color)>>8;
  265.     from.green = WMGreenComponentOfColor(color)>>8;
  266.     from.blue = WMBlueComponentOfColor(color)>>8;
  267.  
  268.     color = WMGetColorWellColor(panel->tcol2W);
  269.     to.red = WMRedComponentOfColor(color)>>8;
  270.     to.green = WMGreenComponentOfColor(color)>>8;
  271.     to.blue = WMBlueComponentOfColor(color)>>8;
  272.  
  273.     image = RRenderGradient(80, 30, &from, &to, RHorizontalGradient);
  274.     pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
  275.                       image, 128);
  276.     RDestroyImage(image);
  277.     WMSetButtonImage(panel->dirhB, pixmap);
  278.     WMReleasePixmap(pixmap);
  279.     
  280.     image = RRenderGradient(80, 30, &from, &to, RVerticalGradient);
  281.     pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
  282.                       image, 128);
  283.     RDestroyImage(image);
  284.     WMSetButtonImage(panel->dirvB, pixmap);
  285.     WMReleasePixmap(pixmap);
  286.     
  287.     image = RRenderGradient(80, 30, &from, &to, RDiagonalGradient);
  288.     pixmap = WMCreatePixmapFromRImage(WMWidgetScreen(panel->gcolL),
  289.                       image, 128);
  290.     RDestroyImage(image);
  291.     WMSetButtonImage(panel->dirdB, pixmap);
  292.     WMReleasePixmap(pixmap);
  293. }
  294.  
  295.  
  296. /*********** Gradient ************/
  297.  
  298. static void
  299. updateSVSlider(WMSlider *sPtr, Bool saturation, WMFont *font, RHSVColor *hsv)
  300. {
  301.     RImage *image;
  302.     WMPixmap *pixmap;
  303.     WMScreen *scr = WMWidgetScreen(sPtr);
  304.     RColor from, to;
  305.     RHSVColor tmp;
  306.  
  307.     tmp = *hsv;
  308.     if (saturation) {
  309.     tmp.saturation = 0;
  310.     RHSVtoRGB(&tmp, &from);
  311.     tmp.saturation = 255;
  312.     RHSVtoRGB(&tmp, &to);
  313.     } else {
  314.     tmp.value = 0;
  315.     RHSVtoRGB(&tmp, &from);
  316.     tmp.value = 255;
  317.     RHSVtoRGB(&tmp, &to);
  318.     }
  319.     image = RRenderGradient(130, 16, &from, &to, RHorizontalGradient);
  320.     pixmap = WMCreatePixmapFromRImage(scr, image, 128);
  321.     RDestroyImage(image);
  322.  
  323.     if (hsv->value < 128 || !saturation) {
  324.     WMColor *col = WMWhiteColor(scr);
  325.  
  326.     WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
  327.              (16 - WMFontHeight(font))/2 - 1,
  328.              saturation ? "Saturation" : "Brightness", 10);
  329.     WMReleaseColor(col);
  330.     } else {
  331.     WMColor *col = WMBlackColor(scr);
  332.  
  333.     WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
  334.              (16 - WMFontHeight(font))/2 - 1,
  335.              saturation ? "Saturation" : "Brightness", 10);
  336.     WMReleaseColor(col);
  337.     }
  338.     WMSetSliderImage(sPtr, pixmap);
  339.     WMReleasePixmap(pixmap);
  340. }
  341.  
  342.  
  343. static void
  344. updateHueSlider(WMSlider *sPtr, WMFont *font, RHSVColor *hsv)
  345. {
  346.     RColor *colors[8];
  347.     RImage *image;
  348.     WMPixmap *pixmap;
  349.     WMScreen *scr = WMWidgetScreen(sPtr);
  350.     RHSVColor thsv;
  351.     int i;
  352.  
  353.     thsv = *hsv;
  354.     for (i = 0; i <= 6; i++) {
  355.         thsv.hue = (360*i)/6;
  356.         colors[i] = wmalloc(sizeof(RColor));
  357.         RHSVtoRGB(&thsv, colors[i]);
  358.     }
  359.     colors[i] = NULL;
  360.  
  361.     image = RRenderMultiGradient(130, 16, colors, RGRD_HORIZONTAL);
  362.     pixmap = WMCreatePixmapFromRImage(scr, image, 128);
  363.     RDestroyImage(image);
  364.  
  365.     if (hsv->value < 128) {
  366.     WMColor *col = WMWhiteColor(scr);
  367.  
  368.     WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
  369.              (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
  370.     WMReleaseColor(col);
  371.     } else {
  372.     WMColor *col = WMBlackColor(scr);
  373.  
  374.     WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(col), font, 2,
  375.              (16 - WMFontHeight(font))/2 - 1, "Hue", 3);
  376.     WMReleaseColor(col);
  377.     }
  378.     WMSetSliderImage(sPtr, pixmap);
  379.     WMReleasePixmap(pixmap);
  380.  
  381.     for (i = 0; i <= 6; i++)
  382.     free(colors[i]);
  383. }
  384.  
  385.  
  386.  
  387. static void
  388. sliderChangeCallback(WMWidget *w, void *data)
  389. {
  390.     TexturePanel *panel = (TexturePanel*)data;
  391.     RHSVColor hsv;
  392.     int row, rows;
  393.     WMListItem *item;
  394.     RColor **colors;
  395.     int i;
  396.     RImage *image;
  397.     WMScreen *scr = WMWidgetScreen(w);
  398.  
  399.     hsv.hue = WMGetSliderValue(panel->ghueS);
  400.     hsv.saturation = WMGetSliderValue(panel->gsatS);
  401.     hsv.value = WMGetSliderValue(panel->gvalS);
  402.  
  403.     row = WMGetListSelectedItemRow(panel->gcolL);
  404.     if (row >= 0) {
  405.     RColor *rgb;
  406.  
  407.     item = WMGetListItem(panel->gcolL, row);
  408.  
  409.     rgb = (RColor*)item->clientData;
  410.  
  411.     RHSVtoRGB(&hsv, rgb);
  412.     
  413.     sprintf(item->text, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
  414.     }
  415.  
  416.     if (w == panel->ghueS) {
  417.     updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
  418.     updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
  419.     } else if (w == panel->gsatS) {
  420.     updateHueSlider(panel->ghueS, panel->listFont, &hsv);
  421.     updateSVSlider(panel->gvalS, False, panel->listFont, &hsv);
  422.     } else {
  423.     updateHueSlider(panel->ghueS, panel->listFont, &hsv);
  424.     updateSVSlider(panel->gsatS, True, panel->listFont, &hsv);
  425.     }
  426.  
  427.     rows = WMGetListNumberOfRows(panel->gcolL);
  428.     if (rows == 0)
  429.     return;
  430.  
  431.     colors = wmalloc(sizeof(RColor*)*(rows+1));
  432.  
  433.     for (i = 0; i < rows; i++) {
  434.     item = WMGetListItem(panel->gcolL, i);
  435.  
  436.     colors[i] = (RColor*)item->clientData;
  437.     }
  438.     colors[i] = NULL;
  439.  
  440.     if (panel->gimage != None) {
  441.     XFreePixmap(WMScreenDisplay(scr), panel->gimage);
  442.     }
  443.  
  444.     image = RRenderMultiGradient(30, i*WMGetListItemHeight(panel->gcolL), 
  445.                  colors, RVerticalGradient);
  446.     RConvertImage(WMScreenRContext(scr), image, &panel->gimage);
  447.     RDestroyImage(image);
  448.  
  449.     free(colors);
  450.  
  451.     WMRedisplayWidget(panel->gcolL);
  452.  
  453.     updateGradButtons(panel);
  454. }
  455.  
  456.  
  457. static void
  458. paintGradListItem(WMList *lPtr, int index, Drawable d, char *text, int state, 
  459.           WMRect *rect)
  460. {
  461.     TexturePanel *panel = (TexturePanel*)WMGetHangedData(lPtr);
  462.     WMScreen *scr = WMWidgetScreen(lPtr);
  463.     int width, height, x, y;
  464.     Display *dpy;
  465.     WMColor *white = WMWhiteColor(scr);
  466.     WMListItem *item;
  467.     WMColor *black = WMBlackColor(scr);
  468.  
  469.     dpy = WMScreenDisplay(scr);
  470.  
  471.     width = rect->size.width;
  472.     height = rect->size.height;
  473.     x = rect->pos.x;
  474.     y = rect->pos.y;
  475.  
  476.     if (state & WLDSSelected)
  477.         XFillRectangle(dpy, d, WMColorGC(white), x, y, width, height);
  478.     else
  479.         XClearArea(dpy, d, x, y, width, height, False);
  480.  
  481.     item = WMGetListItem(lPtr, index);
  482.  
  483.     if (panel->gimage) {
  484.     XCopyArea(WMScreenDisplay(scr), panel->gimage, d, WMColorGC(white),
  485.           0, height*index, 30, height, x + 5, y);
  486.     }
  487.     WMDrawString(scr, d, WMColorGC(black), panel->listFont, 
  488.          x + 40, y + 1, text, strlen(text));
  489.  
  490.     WMReleaseColor(white);
  491.     WMReleaseColor(black);
  492. }
  493.  
  494.  
  495.  
  496. static void
  497. gradAddCallback(WMWidget *w, void *data)
  498. {
  499.     TexturePanel *panel = (TexturePanel*)data;
  500.     WMListItem *item;
  501.     int row;
  502.     RColor *rgb;
  503.  
  504.     row = WMGetListSelectedItemRow(panel->gcolL) + 1;
  505.     item = WMInsertListItem(panel->gcolL, row, "00,00,00");
  506.     rgb = wmalloc(sizeof(RColor));
  507.     memset(rgb, 0, sizeof(RColor));
  508.     item->clientData = rgb;
  509.  
  510.     WMSelectListItem(panel->gcolL, row);
  511.  
  512.     updateGradButtons(panel);
  513.  
  514.     sliderChangeCallback(panel->ghueS, panel);
  515.  
  516.     WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
  517. }
  518.  
  519.  
  520.  
  521. static void
  522. gradClickCallback(WMWidget *w, void *data)
  523. {
  524.     TexturePanel *panel = (TexturePanel*)data;
  525.     WMListItem *item;
  526.     int row;
  527.     RHSVColor hsv;
  528.  
  529.     row = WMGetListSelectedItemRow(w);
  530.     if (row < 0)
  531.     return;
  532.  
  533.     item = WMGetListItem(panel->gcolL, row);
  534.     RRGBtoHSV((RColor*)item->clientData, &hsv);
  535.  
  536.     WMSetSliderValue(panel->ghueS, hsv.hue);
  537.     WMSetSliderValue(panel->gsatS, hsv.saturation);
  538.     WMSetSliderValue(panel->gvalS, hsv.value);
  539.  
  540.     sliderChangeCallback(panel->ghueS, panel);
  541.     sliderChangeCallback(panel->gsatS, panel);
  542. }
  543.  
  544.  
  545. static void
  546. gradDeleteCallback(WMWidget *w, void *data)
  547. {
  548.     TexturePanel *panel = (TexturePanel*)data;
  549.     WMListItem *item;
  550.     int row;
  551.  
  552.     row = WMGetListSelectedItemRow(panel->gcolL);
  553.     if (row < 0)
  554.     return;
  555.  
  556.     item = WMGetListItem(panel->gcolL, row);
  557.     free(item->clientData);
  558.  
  559.     WMRemoveListItem(panel->gcolL, row);
  560.  
  561.     WMSelectListItem(panel->gcolL, row - 1);
  562.  
  563.     updateGradButtons(panel);
  564.  
  565.     gradClickCallback(panel->gcolL, panel);
  566.  
  567.     WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL) > 1);
  568. }
  569.  
  570.  
  571. /*************** Simple Gradient ***************/
  572.  
  573. static void
  574. colorWellObserver(void *self, WMNotification *n)
  575. {
  576.     updateSGradButtons(self);
  577. }
  578.  
  579.  
  580.  
  581.  
  582. static void
  583. opaqChangeCallback(WMWidget *w, void *data)
  584. {
  585.     TexturePanel *panel = (TexturePanel*)data;
  586.  
  587.     updateTGradImage(panel);
  588. }
  589.  
  590. /****************** Image ******************/
  591.  
  592. static void
  593. updateImage(TexturePanel *panel, char *path)
  594. {
  595.     WMScreen *scr = WMWidgetScreen(panel->win);
  596.     RImage *image;
  597.     WMPixmap *pixmap;
  598.     WMSize size;
  599.  
  600.     if (path) {
  601.     image = RLoadImage(WMScreenRContext(scr), path, 0);
  602.     if (!image) {
  603.         char *message;
  604.         
  605.         message = wstrappend(_("Could not load the selected file: "),
  606.                  (char*)RMessageForError(RErrorCode));
  607.  
  608.         WMRunAlertPanel(scr, panel->win, _("Error"), message,
  609.                 _("OK"), NULL, NULL);
  610.  
  611.         if (!panel->image)
  612.         WMSetButtonEnabled(panel->okB, False);
  613.         return;
  614.     }
  615.  
  616.     WMSetButtonEnabled(panel->okB, True);
  617.  
  618.     if (panel->image)
  619.         RDestroyImage(panel->image);
  620.     panel->image = image;
  621.     } else {
  622.     image = panel->image;
  623.     }
  624.     
  625.     if (WMGetPopUpButtonSelectedItem(panel->typeP) == TYPE_PIXMAP) {
  626.     if (image) {
  627.         pixmap = WMCreatePixmapFromRImage(scr, image, 128);
  628.  
  629.         size = WMGetPixmapSize(pixmap);
  630.         WMSetLabelImage(panel->imageL, pixmap);
  631.         WMResizeWidget(panel->imageL, size.width, size.height);
  632.     
  633.         WMReleasePixmap(pixmap);
  634.     }
  635.     } else {
  636.     updateTGradImage(panel);
  637.     }
  638. }
  639.  
  640.  
  641. static void
  642. browseImageCallback(WMWidget *w, void *data)
  643. {
  644.     TexturePanel *panel = (TexturePanel*)data;
  645.     WMOpenPanel *opanel;
  646.     WMScreen *scr = WMWidgetScreen(w);
  647.     static char *ipath = NULL;
  648.  
  649.     opanel = WMGetOpenPanel(scr);
  650.     WMSetFilePanelCanChooseDirectories(opanel, False);
  651.     WMSetFilePanelCanChooseFiles(opanel, True);
  652.  
  653.     if (!ipath)
  654.     ipath = wstrdup(wgethomedir());
  655.     
  656.     if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath,
  657.                     "Open Image", NULL)) {
  658.     char *path, *fullpath;
  659.     char *tmp, *tmp2;
  660.  
  661.     tmp = WMGetFilePanelFileName(opanel);
  662.     if (!tmp)
  663.         return;
  664.     fullpath = tmp;
  665.  
  666.     free(ipath);
  667.     ipath = fullpath;
  668.  
  669.     path = wstrdup(fullpath);
  670.  
  671.     tmp2 = strrchr(fullpath, '/');
  672.     if (tmp2)
  673.         tmp2++;
  674.  
  675.     tmp = wfindfileinarray(panel->pathList, tmp2);
  676.  
  677.     if (tmp) {
  678.         if (strcmp(fullpath, tmp)==0) {
  679.         free(path);
  680.         path = tmp2;
  681.         }
  682.         free(tmp);
  683.     }
  684.  
  685.     if (!RGetImageFileFormat(fullpath)) {
  686.         WMRunAlertPanel(scr, panel->win, _("Error"),
  687.                 _("The selected file does not contain a supported image."),
  688.                 _("OK"), NULL, NULL);
  689.         free(path);
  690.     } else {
  691.         updateImage(panel, fullpath);
  692.         free(panel->imageFile);
  693.         panel->imageFile = path;
  694.  
  695.         WMSetTextFieldText(panel->imageT, path);
  696.     }
  697.     }
  698. }
  699.  
  700.  
  701.  
  702. static void
  703. buttonCallback(WMWidget *w, void *data)
  704. {
  705.     TexturePanel *panel = (TexturePanel*)data;
  706.     
  707.     if (w == panel->okB) {
  708.     (*panel->okAction)(panel->okData);
  709.     } else {
  710.     (*panel->cancelAction)(panel->cancelData);
  711.     }
  712. }
  713.  
  714.  
  715.  
  716. static void
  717. changeTypeCallback(WMWidget *w, void *data)
  718. {
  719.     TexturePanel *panel = (TexturePanel*)data;
  720.     int newType;
  721.     int i;
  722.  
  723.     newType = WMGetPopUpButtonSelectedItem(w);
  724.     if (newType == panel->currentType)
  725.     return;
  726.  
  727.     if (panel->currentType >= 0) {
  728.     for (i = 0; i < MAX_SECTION_PARTS; i++) {
  729.         if (panel->sectionParts[panel->currentType][i] == NULL)
  730.         break;
  731.         WMUnmapWidget(panel->sectionParts[panel->currentType][i]);
  732.     }
  733.     }
  734.  
  735.     for (i = 0; i < MAX_SECTION_PARTS; i++) {
  736.     if (panel->sectionParts[newType][i] == NULL)
  737.         break;
  738.     WMMapWidget(panel->sectionParts[newType][i]);
  739.     }
  740.     panel->currentType = newType;
  741.  
  742.     switch (newType) {
  743.      case TYPE_SGRADIENT:
  744.     updateSGradButtons(panel);
  745.     WMSetButtonEnabled(panel->okB, True);
  746.     break;
  747.      case TYPE_GRADIENT:
  748.     updateGradButtons(panel);
  749.     WMSetButtonEnabled(panel->okB, WMGetListNumberOfRows(panel->gcolL)>1);
  750.     break;
  751.      case TYPE_TGRADIENT:
  752.      case TYPE_PIXMAP:
  753.     updateImage(panel, NULL);
  754.     WMSetButtonEnabled(panel->okB, panel->image!=NULL);
  755.     break;
  756.      default:
  757.     WMSetButtonEnabled(panel->okB, True);
  758.     break;
  759.     }
  760. }
  761.  
  762.  
  763. /*
  764.  *--------------------------------------------------------------------------
  765.  * Public functions
  766.  *--------------------------------------------------------------------------
  767.  */
  768. void
  769. DestroyTexturePanel(TexturePanel *panel)
  770. {
  771.  
  772. }
  773.  
  774.  
  775. void
  776. ShowTexturePanel(TexturePanel *panel)
  777. {
  778.     Display *dpy = WMScreenDisplay(WMWidgetScreen(panel->win));
  779.     Screen *scr = DefaultScreenOfDisplay(dpy);
  780.  
  781.     WMSetWindowInitialPosition(panel->win,
  782.              (WidthOfScreen(scr)-WMWidgetWidth(panel->win))/2,
  783.              (HeightOfScreen(scr)-WMWidgetHeight(panel->win))/2);
  784.     WMMapWidget(panel->win);
  785. }
  786.  
  787.  
  788. void
  789. HideTexturePanel(TexturePanel *panel)
  790. {
  791.     WMUnmapWidget(panel->win);
  792. }
  793.  
  794.  
  795. void
  796. SetTexturePanelOkAction(TexturePanel *panel, WMCallback *action, void *clientData)
  797. {
  798.     panel->okAction = action;
  799.     panel->okData = clientData;
  800. }
  801.  
  802.  
  803. void
  804. SetTexturePanelCancelAction(TexturePanel *panel, WMCallback *action, void *clientData)
  805. {
  806.     panel->cancelAction = action;
  807.     panel->cancelData = clientData;
  808. }
  809.  
  810.  
  811. void
  812. SetTexturePanelTexture(TexturePanel *panel, char *name, proplist_t texture)
  813. {
  814.     WMScreen *scr = WMWidgetScreen(panel->win);
  815.     char *str, *type;
  816.     proplist_t p;
  817.     WMColor *color;
  818.     int i;
  819.     char buffer[64];
  820.     int gradient = 0;
  821.  
  822.     WMSetTextFieldText(panel->nameT, name);
  823.  
  824.     if (!texture)
  825.     return;
  826.  
  827.     p = PLGetArrayElement(texture, 0);
  828.     if (!p) {
  829.     goto bad_texture;
  830.     }
  831.     type = PLGetString(p);
  832.  
  833.     /*...............................................*/
  834.     if (strcasecmp(type, "solid")==0) {
  835.  
  836.     WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SOLID);
  837.  
  838.     p = PLGetArrayElement(texture, 1);
  839.     if (!p) {
  840.         str = "black";
  841.     } else {
  842.         str = PLGetString(p);
  843.     }
  844.     color = WMCreateNamedColor(scr, str, False);
  845.  
  846.     WMSetColorWellColor(panel->defcW, color);
  847.  
  848.     WMReleaseColor(color);
  849.     /*...............................................*/
  850.     } else if (strcasecmp(type, "hgradient")==0
  851.            || strcasecmp(type, "vgradient")==0
  852.            || strcasecmp(type, "dgradient")==0) {
  853.  
  854.     WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_SGRADIENT);
  855.  
  856.     p = PLGetArrayElement(texture, 1);
  857.     if (!p) {
  858.         str = "black";
  859.     } else {
  860.         str = PLGetString(p);
  861.     }
  862.     color = WMCreateNamedColor(scr, str, False);
  863.  
  864.     WMSetColorWellColor(panel->tcol1W, color);
  865.  
  866.     WMReleaseColor(color);
  867.  
  868.     p = PLGetArrayElement(texture, 2);
  869.     if (!p) {
  870.         str = "black";
  871.     } else {
  872.         str = PLGetString(p);
  873.     }
  874.     color = WMCreateNamedColor(scr, str, False);
  875.  
  876.     WMSetColorWellColor(panel->tcol2W, color);
  877.  
  878.     WMReleaseColor(color);
  879.  
  880.     gradient = type[0];
  881.     /*...............................................*/
  882.     } else if (strcasecmp(type, "thgradient")==0
  883.            || strcasecmp(type, "tvgradient")==0
  884.            || strcasecmp(type, "tdgradient")==0) {
  885.     int i;
  886.  
  887.     WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_TGRADIENT);
  888.  
  889.     gradient = type[1];
  890.  
  891.     WMSetTextFieldText(panel->imageT,
  892.                PLGetString(PLGetArrayElement(texture, 1)));
  893.     if (panel->imageFile)
  894.         free(panel->imageFile);
  895.     panel->imageFile = wstrdup(PLGetString(PLGetArrayElement(texture, 1)));
  896.  
  897.  
  898.     i = 180;
  899.     sscanf(PLGetString(PLGetArrayElement(texture, 2)), "%i", &i);
  900.     WMSetSliderValue(panel->topaS, i);
  901.  
  902.     p = PLGetArrayElement(texture, 3);
  903.     if (!p) {
  904.         str = "black";
  905.     } else {
  906.         str = PLGetString(p);
  907.     }
  908.     color = WMCreateNamedColor(scr, str, False);
  909.  
  910.     WMSetColorWellColor(panel->tcol1W, color);
  911.  
  912.     WMReleaseColor(color);
  913.  
  914.     p = PLGetArrayElement(texture, 4);
  915.     if (!p) {
  916.         str = "black";
  917.     } else {
  918.         str = PLGetString(p);
  919.     }
  920.     color = WMCreateNamedColor(scr, str, False);
  921.  
  922.     WMSetColorWellColor(panel->tcol2W, color);
  923.  
  924.     WMReleaseColor(color);
  925.     
  926.     WMSetTextFieldText(panel->imageT,
  927.                PLGetString(PLGetArrayElement(texture, 1)));
  928.     
  929.     if (panel->imageFile)
  930.         free(panel->imageFile);
  931.     if ((panel->imageFile = wfindfileinarray(panel->pathList,
  932.                 PLGetString(PLGetArrayElement(texture, 1)))) != NULL) {
  933.  
  934.         panel->image = RLoadImage(WMScreenRContext(scr), panel->imageFile, 0);
  935.         updateTGradImage(panel);
  936.  
  937.         updateSGradButtons(panel);
  938.     } else wwarning("could not load file '%s': %s", panel->imageFile,
  939.              RMessageForError(RErrorCode));
  940.  
  941.     /*...............................................*/
  942.     } else if (strcasecmp(type, "mhgradient")==0
  943.            || strcasecmp(type, "mvgradient")==0
  944.            || strcasecmp(type, "mdgradient")==0) {
  945.     WMListItem *item;
  946.  
  947.     for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
  948.         item = WMGetListItem(panel->gcolL, i);
  949.         free(item->clientData);
  950.     }
  951.     WMClearList(panel->gcolL);
  952.  
  953.     WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_GRADIENT);
  954.  
  955.     p = PLGetArrayElement(texture, 1);
  956.     if (!p) {
  957.         str = "black";
  958.     } else {
  959.         str = PLGetString(p);
  960.     }
  961.     color = WMCreateNamedColor(scr, str, False);
  962.  
  963.     WMSetColorWellColor(panel->defcW, color);
  964.  
  965.     WMReleaseColor(color);
  966.  
  967.     for (i = 2; i < PLGetNumberOfElements(texture); i++) {
  968.         RColor *rgb;
  969.         XColor xcolor;
  970.  
  971.         p = PLGetArrayElement(texture, i);
  972.         if (!p) {
  973.         str = "black";
  974.         } else {
  975.         str = PLGetString(p);
  976.         }
  977.  
  978.         XParseColor(WMScreenDisplay(scr), WMScreenRContext(scr)->cmap,
  979.             str, &xcolor);
  980.  
  981.         rgb = wmalloc(sizeof(RColor));
  982.         rgb->red = xcolor.red >> 8;
  983.         rgb->green = xcolor.green >> 8;
  984.         rgb->blue = xcolor.blue >> 8;
  985.         sprintf(buffer, "%02x,%02x,%02x", rgb->red, rgb->green, rgb->blue);
  986.  
  987.         item = WMAddListItem(panel->gcolL, buffer);
  988.         item->clientData = rgb;
  989.     }
  990.  
  991.     sliderChangeCallback(panel->ghueS, panel);
  992.  
  993.     gradient = type[1];
  994.     /*...............................................*/
  995.     } else if (strcasecmp(type, "cpixmap")==0
  996.            || strcasecmp(type, "spixmap")==0
  997.            || strcasecmp(type, "mpixmap")==0
  998.            || strcasecmp(type, "tpixmap")==0) {
  999.  
  1000.     WMSetPopUpButtonSelectedItem(panel->typeP, TYPE_PIXMAP);
  1001.  
  1002.     switch (toupper(type[0])) {
  1003.      case 'C':
  1004.         WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_CENTER);
  1005.         break;
  1006.      case 'S':
  1007.         WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_SCALE);
  1008.         break;
  1009.      case 'M':
  1010.         WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_MAXIMIZE);
  1011.         break;
  1012.      default:
  1013.      case 'T':
  1014.         WMSetPopUpButtonSelectedItem(panel->arrP, PTYPE_TILE);
  1015.         break;
  1016.     }
  1017.  
  1018.     WMSetTextFieldText(panel->imageT,
  1019.                PLGetString(PLGetArrayElement(texture, 1)));
  1020.     
  1021.     if (panel->imageFile)
  1022.         free(panel->imageFile);
  1023.     panel->imageFile = wfindfileinarray(panel->pathList,
  1024.                 PLGetString(PLGetArrayElement(texture, 1)));
  1025.  
  1026.     color = WMCreateNamedColor(scr,
  1027.                PLGetString(PLGetArrayElement(texture, 2)), False);
  1028.     WMSetColorWellColor(panel->defcW, color);
  1029.     WMReleaseColor(color);
  1030.  
  1031.     updateImage(panel, panel->imageFile);
  1032.     }
  1033.  
  1034.     changeTypeCallback(panel->typeP, panel);
  1035.  
  1036.     if (gradient > 0) {
  1037.     updateGradButtons(panel);
  1038.  
  1039.     switch (toupper(gradient)) {
  1040.      case 'H':
  1041.         WMPerformButtonClick(panel->dirhB);
  1042.         break;
  1043.      case 'V':
  1044.         WMPerformButtonClick(panel->dirvB);
  1045.         break;
  1046.      default:
  1047.      case 'D':
  1048.         WMPerformButtonClick(panel->dirdB);
  1049.         break;
  1050.     }
  1051.     }
  1052.  
  1053.     return;
  1054.  
  1055.  bad_texture:
  1056.     str = PLGetDescription(texture);
  1057.     wwarning("error creating texture %s", str);
  1058.     free(str);
  1059.  
  1060. }
  1061.  
  1062.  
  1063.  
  1064. char*
  1065. GetTexturePanelTextureName(TexturePanel *panel)
  1066. {
  1067.     return WMGetTextFieldText(panel->nameT);
  1068.  
  1069. }
  1070.  
  1071.  
  1072.  
  1073. proplist_t
  1074. GetTexturePanelTexture(TexturePanel *panel)
  1075. {
  1076.     proplist_t prop = NULL;
  1077.     WMColor *color;
  1078.     char *str, *str2;
  1079.     char buff[32];
  1080.     int i;
  1081.  
  1082.  
  1083.     switch (WMGetPopUpButtonSelectedItem(panel->typeP)) {
  1084.  
  1085.      case TYPE_SOLID:
  1086.     color = WMGetColorWellColor(panel->defcW);
  1087.     str = WMGetColorRGBDescription(color);
  1088.     prop = PLMakeArrayFromElements(PLMakeString("solid"),
  1089.                        PLMakeString(str), NULL);
  1090.     free(str);
  1091.  
  1092.     break;
  1093.  
  1094.      case TYPE_PIXMAP:
  1095.     color = WMGetColorWellColor(panel->defcW);
  1096.     str = WMGetColorRGBDescription(color);
  1097.  
  1098.     switch (WMGetPopUpButtonSelectedItem(panel->arrP)) {
  1099.      case PTYPE_SCALE:
  1100.         prop = PLMakeArrayFromElements(PLMakeString("spixmap"), 
  1101.                        PLMakeString(panel->imageFile),
  1102.                        PLMakeString(str), NULL);
  1103.         break;
  1104.      case PTYPE_MAXIMIZE:
  1105.         prop = PLMakeArrayFromElements(PLMakeString("mpixmap"), 
  1106.                        PLMakeString(panel->imageFile),
  1107.                        PLMakeString(str), NULL);
  1108.         break;
  1109.      case PTYPE_CENTER:
  1110.         prop = PLMakeArrayFromElements(PLMakeString("cpixmap"), 
  1111.                        PLMakeString(panel->imageFile),
  1112.                        PLMakeString(str), NULL);
  1113.         break;
  1114.      case PTYPE_TILE:
  1115.         prop = PLMakeArrayFromElements(PLMakeString("tpixmap"),
  1116.                        PLMakeString(panel->imageFile),
  1117.                        PLMakeString(str), NULL);
  1118.         break;
  1119.     }
  1120.     free(str);
  1121.     break;
  1122.  
  1123.      case TYPE_TGRADIENT:
  1124.     color = WMGetColorWellColor(panel->tcol1W);
  1125.     str = WMGetColorRGBDescription(color);
  1126.  
  1127.     color = WMGetColorWellColor(panel->tcol2W);
  1128.     str2 = WMGetColorRGBDescription(color);
  1129.  
  1130.     sprintf(buff, "%i", WMGetSliderValue(panel->topaS));
  1131.  
  1132.     if (WMGetButtonSelected(panel->dirdB)) {
  1133.         prop = PLMakeArrayFromElements(PLMakeString("tdgradient"),
  1134.                        PLMakeString(panel->imageFile),
  1135.                        PLMakeString(buff),
  1136.                        PLMakeString(str),
  1137.                        PLMakeString(str2), NULL);
  1138.     } else     if (WMGetButtonSelected(panel->dirvB)) {
  1139.         prop = PLMakeArrayFromElements(PLMakeString("tvgradient"),
  1140.                        PLMakeString(panel->imageFile),
  1141.                        PLMakeString(buff),
  1142.                        PLMakeString(str),
  1143.                        PLMakeString(str2), NULL);
  1144.     } else {
  1145.         prop = PLMakeArrayFromElements(PLMakeString("thgradient"),
  1146.                        PLMakeString(panel->imageFile),
  1147.                        PLMakeString(buff),
  1148.                        PLMakeString(str),
  1149.                        PLMakeString(str2), NULL);
  1150.     }
  1151.     free(str);
  1152.     free(str2);
  1153.     break;
  1154.  
  1155.  
  1156.      case TYPE_SGRADIENT:
  1157.     color = WMGetColorWellColor(panel->tcol1W);
  1158.     str = WMGetColorRGBDescription(color);
  1159.  
  1160.     color = WMGetColorWellColor(panel->tcol2W);
  1161.     str2 = WMGetColorRGBDescription(color);
  1162.     
  1163.     if (WMGetButtonSelected(panel->dirdB)) {
  1164.         prop = PLMakeArrayFromElements(PLMakeString("dgradient"),
  1165.                        PLMakeString(str),
  1166.                        PLMakeString(str2), NULL);
  1167.     } else     if (WMGetButtonSelected(panel->dirvB)) {
  1168.         prop = PLMakeArrayFromElements(PLMakeString("vgradient"),
  1169.                        PLMakeString(str),
  1170.                        PLMakeString(str2), NULL);
  1171.     } else {
  1172.         prop = PLMakeArrayFromElements(PLMakeString("hgradient"),
  1173.                        PLMakeString(str),
  1174.                        PLMakeString(str2), NULL);
  1175.     }
  1176.     free(str);
  1177.     free(str2);
  1178.     break;
  1179.  
  1180.      case TYPE_GRADIENT:
  1181.     color = WMGetColorWellColor(panel->defcW);
  1182.     str = WMGetColorRGBDescription(color);
  1183.  
  1184.     if (WMGetButtonSelected(panel->dirdB)) {
  1185.         prop = PLMakeArrayFromElements(PLMakeString("mdgradient"),
  1186.                        PLMakeString(str), NULL);
  1187.     } else     if (WMGetButtonSelected(panel->dirvB)) {
  1188.         prop = PLMakeArrayFromElements(PLMakeString("mvgradient"),
  1189.                        PLMakeString(str), NULL);
  1190.     } else {
  1191.         prop = PLMakeArrayFromElements(PLMakeString("mhgradient"),
  1192.                        PLMakeString(str), NULL);
  1193.     }
  1194.     free(str);
  1195.  
  1196.     for (i = 0; i < WMGetListNumberOfRows(panel->gcolL); i++) {
  1197.         RColor *rgb;
  1198.         WMListItem *item;
  1199.         
  1200.         item = WMGetListItem(panel->gcolL, i);
  1201.         
  1202.         rgb = (RColor*)item->clientData;
  1203.  
  1204.         sprintf(buff, "#%02x%02x%02x", rgb->red, rgb->green, rgb->blue);
  1205.  
  1206.         PLAppendArrayElement(prop, PLMakeString(buff));
  1207.     }
  1208.     break;
  1209.     }
  1210.  
  1211.  
  1212.     return prop;
  1213. }
  1214.  
  1215.  
  1216.  
  1217. void
  1218. SetTexturePanelPixmapPath(TexturePanel *panel, proplist_t array)
  1219. {
  1220.     panel->pathList = array;
  1221. }
  1222.  
  1223.  
  1224.  
  1225. TexturePanel*
  1226. CreateTexturePanel(WMWindow *keyWindow)
  1227. /*CreateTexturePanel(WMScreen *scr)*/
  1228. {
  1229.     TexturePanel *panel;
  1230.     WMScreen *scr = WMWidgetScreen(keyWindow);
  1231.  
  1232.     panel = wmalloc(sizeof(TexturePanel));
  1233.     memset(panel, 0, sizeof(TexturePanel));
  1234.  
  1235.     panel->listFont = WMSystemFontOfSize(scr, 12);
  1236.  
  1237.  
  1238.     panel->win = WMCreatePanelWithStyleForWindow(keyWindow, "texturePanel",
  1239.                          WMTitledWindowMask
  1240.                          |WMClosableWindowMask);
  1241.  /*
  1242.     panel->win = WMCreateWindowWithStyle(scr, "texturePanel",
  1243.                      WMTitledWindowMask
  1244.                      |WMClosableWindowMask);
  1245.   */
  1246.  
  1247.     WMResizeWidget(panel->win, 325, 423);
  1248.     WMSetWindowTitle(panel->win, _("Texture Panel"));
  1249.     WMSetWindowCloseAction(panel->win, buttonCallback, panel);
  1250.  
  1251.  
  1252.     /* texture name */
  1253.     panel->nameF = WMCreateFrame(panel->win);
  1254.     WMResizeWidget(panel->nameF, 185, 50);
  1255.     WMMoveWidget(panel->nameF, 15, 10);
  1256.     WMSetFrameTitle(panel->nameF, _("Texture Name"));
  1257.  
  1258.     panel->nameT = WMCreateTextField(panel->nameF);
  1259.     WMResizeWidget(panel->nameT, 160, 20);
  1260.     WMMoveWidget(panel->nameT, 12, 18);
  1261.  
  1262.     WMMapSubwidgets(panel->nameF);
  1263.  
  1264.     /* texture types */
  1265.     panel->typeP = WMCreatePopUpButton(panel->win);
  1266.     WMResizeWidget(panel->typeP, 185, 20);
  1267.     WMMoveWidget(panel->typeP, 15, 65);
  1268.     WMAddPopUpButtonItem(panel->typeP, _("Solid Color"));
  1269.     WMAddPopUpButtonItem(panel->typeP, _("Gradient Texture"));
  1270.     WMAddPopUpButtonItem(panel->typeP, _("Simple Gradient Texture"));
  1271.     WMAddPopUpButtonItem(panel->typeP, _("Textured Gradient"));
  1272.     WMAddPopUpButtonItem(panel->typeP, _("Image Texture"));
  1273.     WMSetPopUpButtonSelectedItem(panel->typeP, 0);
  1274.     WMSetPopUpButtonAction(panel->typeP, changeTypeCallback, panel);
  1275.  
  1276.     /* color */
  1277.     panel->defcF = WMCreateFrame(panel->win);
  1278.     WMResizeWidget(panel->defcF, 100, 75);
  1279.     WMMoveWidget(panel->defcF, 210, 10);
  1280.     WMSetFrameTitle(panel->defcF, _("Default Color"));
  1281.  
  1282.     panel->defcW = WMCreateColorWell(panel->defcF);
  1283.     WMResizeWidget(panel->defcW, 60, 45);
  1284.     WMMoveWidget(panel->defcW, 20, 20);
  1285.  
  1286.     WMMapSubwidgets(panel->defcF);
  1287.  
  1288.     /****** Gradient ******/
  1289.     panel->gcolF = WMCreateFrame(panel->win);
  1290.     WMResizeWidget(panel->gcolF, 295, 205);
  1291.     WMMoveWidget(panel->gcolF, 15, 95);
  1292.     WMSetFrameTitle(panel->gcolF, _("Gradient Colors"));
  1293.  
  1294.     panel->gcolL = WMCreateList(panel->gcolF);
  1295.     WMResizeWidget(panel->gcolL, 130, 140);
  1296.     WMMoveWidget(panel->gcolL, 10, 25);
  1297.     WMHangData(panel->gcolL, panel);
  1298.     WMSetListUserDrawProc(panel->gcolL, paintGradListItem);
  1299.     WMSetListAction(panel->gcolL, gradClickCallback, panel);
  1300.  
  1301.     panel->gcolaB = WMCreateCommandButton(panel->gcolF);
  1302.     WMResizeWidget(panel->gcolaB, 64, 24);
  1303.     WMMoveWidget(panel->gcolaB, 10, 170);
  1304.     WMSetButtonText(panel->gcolaB, _("Add"));
  1305.     WMSetButtonAction(panel->gcolaB, gradAddCallback, panel);
  1306.     
  1307.     panel->gcoldB = WMCreateCommandButton(panel->gcolF);
  1308.     WMResizeWidget(panel->gcoldB, 64, 24);
  1309.     WMMoveWidget(panel->gcoldB, 75, 170);
  1310.     WMSetButtonText(panel->gcoldB, _("Delete"));
  1311.     WMSetButtonAction(panel->gcoldB, gradDeleteCallback, panel);
  1312.  
  1313. #if 0
  1314.     panel->gbriS = WMCreateSlider(panel->gcolF);
  1315.     WMResizeWidget(panel->gbriS, 130, 16);
  1316.     WMMoveWidget(panel->gbriS, 150, 25);
  1317.     WMSetSliderKnobThickness(panel->gbriS, 8);
  1318.     WMSetSliderMaxValue(panel->gbriS, 100);
  1319.     WMSetSliderAction(panel->gbriS, sliderChangeCallback, panel);
  1320.     {
  1321.     WMPixmap *pixmap;
  1322.     WMColor *color;
  1323.  
  1324.     pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
  1325.     color = WMDarkGrayColor(scr);
  1326.     XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
  1327.                WMColorGC(color), 0, 0, 130, 16);
  1328.     WMReleaseColor(color);
  1329.     color = WMWhiteColor(color);
  1330.     WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color),
  1331.              panel->listFont, 2, 
  1332.              (16 - WMFontHeight(panel->listFont))/2 - 1,
  1333.              "Brightness", 10);
  1334.     WMSetSliderImage(panel->gbriS, pixmap);
  1335.     WMReleasePixmap(pixmap);
  1336.     }
  1337.  
  1338.     panel->gconS = WMCreateSlider(panel->gcolF);
  1339.     WMResizeWidget(panel->gconS, 130, 16);
  1340.     WMMoveWidget(panel->gconS, 150, 50);
  1341.     WMSetSliderKnobThickness(panel->gconS, 8);
  1342.     WMSetSliderMaxValue(panel->gconS, 100);
  1343.     WMSetSliderAction(panel->gconS, sliderChangeCallback, panel);
  1344.     {
  1345.     WMPixmap *pixmap;
  1346.     WMColor *color;
  1347.  
  1348.     pixmap = WMCreatePixmap(scr, 130, 16, WMScreenDepth(scr), False);
  1349.     color = WMDarkGrayColor(scr);
  1350.     XFillRectangle(WMScreenDisplay(scr), WMGetPixmapXID(pixmap),
  1351.                WMColorGC(color), 0, 0, 130, 16);
  1352.     WMReleaseColor(color);
  1353.     color = WMWhiteColor(scr);
  1354.     WMDrawString(scr, WMGetPixmapXID(pixmap), WMColorGC(color), 
  1355.              panel->listFont, 2,
  1356.              (16 - WMFontHeight(panel->listFont))/2 - 1,
  1357.              "Contrast", 8);
  1358.     WMSetSliderImage(panel->gconS, pixmap);
  1359.     WMReleasePixmap(pixmap);
  1360.     }
  1361. #endif
  1362.     panel->ghueS = WMCreateSlider(panel->gcolF);
  1363.     WMResizeWidget(panel->ghueS, 130, 16);
  1364.     WMMoveWidget(panel->ghueS, 150, 100);
  1365.     WMSetSliderKnobThickness(panel->ghueS, 8);
  1366.     WMSetSliderMaxValue(panel->ghueS, 359);
  1367.     WMSetSliderAction(panel->ghueS, sliderChangeCallback, panel);
  1368.  
  1369.     panel->gsatS = WMCreateSlider(panel->gcolF);
  1370.     WMResizeWidget(panel->gsatS, 130, 16);
  1371.     WMMoveWidget(panel->gsatS, 150, 125);
  1372.     WMSetSliderKnobThickness(panel->gsatS, 8);
  1373.     WMSetSliderMaxValue(panel->gsatS, 255);
  1374.     WMSetSliderAction(panel->gsatS, sliderChangeCallback, panel);
  1375.  
  1376.     panel->gvalS = WMCreateSlider(panel->gcolF);
  1377.     WMResizeWidget(panel->gvalS, 130, 16);
  1378.     WMMoveWidget(panel->gvalS, 150, 150);
  1379.     WMSetSliderKnobThickness(panel->gvalS, 8);
  1380.     WMSetSliderMaxValue(panel->gvalS, 255);
  1381.     WMSetSliderAction(panel->gvalS, sliderChangeCallback, panel);
  1382.  
  1383.  
  1384.     WMMapSubwidgets(panel->gcolF);
  1385.  
  1386.     /** Direction **/
  1387.     panel->dirF = WMCreateFrame(panel->win);
  1388.     WMSetFrameTitle(panel->dirF, _("Direction"));
  1389.     WMResizeWidget(panel->dirF, 295, 75);
  1390.     WMMoveWidget(panel->dirF, 15, 305);
  1391.  
  1392.     panel->dirvB = WMCreateButton(panel->dirF, WBTOnOff);
  1393.     WMSetButtonImagePosition(panel->dirvB, WIPImageOnly);
  1394.     WMResizeWidget(panel->dirvB, 90, 40);
  1395.     WMMoveWidget(panel->dirvB, 10, 20);
  1396.  
  1397.     panel->dirhB = WMCreateButton(panel->dirF, WBTOnOff);
  1398.     WMSetButtonImagePosition(panel->dirhB, WIPImageOnly);
  1399.     WMResizeWidget(panel->dirhB, 90, 40);
  1400.     WMMoveWidget(panel->dirhB, 102, 20);
  1401.  
  1402.     panel->dirdB = WMCreateButton(panel->dirF, WBTOnOff);
  1403.     WMSetButtonImagePosition(panel->dirdB, WIPImageOnly);
  1404.     WMResizeWidget(panel->dirdB, 90, 40);
  1405.     WMMoveWidget(panel->dirdB, 194, 20);
  1406.  
  1407.     WMGroupButtons(panel->dirvB, panel->dirhB);
  1408.     WMGroupButtons(panel->dirvB, panel->dirdB);
  1409.  
  1410.     WMMapSubwidgets(panel->dirF);
  1411.  
  1412.     /****************** Textured Gradient ******************/
  1413.     panel->tcolF = WMCreateFrame(panel->win);
  1414.     WMResizeWidget(panel->tcolF, 100, 135);
  1415.     WMMoveWidget(panel->tcolF, 210, 10);
  1416.     WMSetFrameTitle(panel->tcolF, _("Gradient"));
  1417.  
  1418.     panel->tcol1W = WMCreateColorWell(panel->tcolF);
  1419.     WMResizeWidget(panel->tcol1W, 60, 45);
  1420.     WMMoveWidget(panel->tcol1W, 20, 25);
  1421.     WMAddNotificationObserver(colorWellObserver, panel,
  1422.                   WMColorWellDidChangeNotification, panel->tcol1W);
  1423.  
  1424.     panel->tcol2W = WMCreateColorWell(panel->tcolF);
  1425.     WMResizeWidget(panel->tcol2W, 60, 45);
  1426.     WMMoveWidget(panel->tcol2W, 20, 75);
  1427.     WMAddNotificationObserver(colorWellObserver, panel,
  1428.                   WMColorWellDidChangeNotification, panel->tcol2W);
  1429.  
  1430.     /** Opacity */
  1431.     panel->topaF = WMCreateFrame(panel->win);
  1432.     WMResizeWidget(panel->topaF, 185, 50);
  1433.     WMMoveWidget(panel->topaF, 15, 95);
  1434.     WMSetFrameTitle(panel->topaF, _("Gradient Opacity"));
  1435.  
  1436.     panel->topaS = WMCreateSlider(panel->topaF);
  1437.     WMResizeWidget(panel->topaS, 155, 18);
  1438.     WMMoveWidget(panel->topaS, 15, 20);
  1439.     WMSetSliderMaxValue(panel->topaS, 255);
  1440.     WMSetSliderValue(panel->topaS, 200);
  1441.     WMSetSliderContinuous(panel->topaS, False);
  1442.     WMSetSliderAction(panel->topaS, opaqChangeCallback, panel);
  1443.     
  1444.     WMMapSubwidgets(panel->topaF);
  1445.  
  1446.     {
  1447.     WMPixmap *pixmap;
  1448.     Pixmap p;
  1449.     WMColor *color;
  1450.  
  1451.     pixmap = WMCreatePixmap(scr, 155, 18, WMScreenDepth(scr), False);
  1452.     p = WMGetPixmapXID(pixmap);
  1453.  
  1454.     color = WMDarkGrayColor(scr);
  1455.     XFillRectangle(WMScreenDisplay(scr), p, WMColorGC(color),
  1456.                0, 0, 155, 18);
  1457.     WMReleaseColor(color);
  1458.  
  1459.     color = WMWhiteColor(scr);
  1460.     WMDrawString(scr, p, WMColorGC(color), panel->listFont,
  1461.              2, 1, "0%", 2);
  1462.     WMDrawString(scr, p, WMColorGC(color), panel->listFont,
  1463.              153 - WMWidthOfString(panel->listFont, "100%", 4), 1,
  1464.              "100%", 4);
  1465.     WMReleaseColor(color);
  1466.  
  1467.     WMSetSliderImage(panel->topaS, pixmap);
  1468.     WMReleasePixmap(pixmap);
  1469.     }
  1470.  
  1471.     WMMapSubwidgets(panel->tcolF);
  1472.  
  1473.     /****************** Image ******************/
  1474.     panel->imageF = WMCreateFrame(panel->win);
  1475.     WMResizeWidget(panel->imageF, 295, 150);
  1476.     WMMoveWidget(panel->imageF, 15, 150);
  1477.     WMSetFrameTitle(panel->imageF, _("Image"));
  1478.  
  1479.     panel->imageL = WMCreateLabel(panel->imageF);
  1480.     WMSetLabelImagePosition(panel->imageL, WIPImageOnly);
  1481.  
  1482.     panel->imageT = WMCreateTextField(panel->imageF);
  1483.     WMResizeWidget(panel->imageT, 90, 20);
  1484.     WMMoveWidget(panel->imageT, 190, 25);
  1485.  
  1486.     panel->imageV = WMCreateScrollView(panel->imageF);
  1487.     WMResizeWidget(panel->imageV, 165, 115);
  1488.     WMMoveWidget(panel->imageV, 15, 20);
  1489.     WMSetScrollViewRelief(panel->imageV, WRSunken);
  1490.     WMSetScrollViewHasHorizontalScroller(panel->imageV, True);
  1491.     WMSetScrollViewHasVerticalScroller(panel->imageV, True);
  1492.     WMSetScrollViewContentView(panel->imageV, WMWidgetView(panel->imageL));
  1493.  
  1494.     panel->browB = WMCreateCommandButton(panel->imageF);
  1495.     WMResizeWidget(panel->browB, 90, 24);
  1496.     WMMoveWidget(panel->browB, 190, 50);
  1497.     WMSetButtonText(panel->browB, _("Browse..."));
  1498.     WMSetButtonAction(panel->browB, browseImageCallback, panel);
  1499.  
  1500. /*    panel->dispB = WMCreateCommandButton(panel->imageF);
  1501.     WMResizeWidget(panel->dispB, 90, 24);
  1502.     WMMoveWidget(panel->dispB, 190, 80);
  1503.     WMSetButtonText(panel->dispB, _("Show"));
  1504.  */
  1505.  
  1506.     panel->arrP = WMCreatePopUpButton(panel->imageF);
  1507.     WMResizeWidget(panel->arrP, 90, 20);
  1508.     WMMoveWidget(panel->arrP, 190, 120);
  1509.     WMAddPopUpButtonItem(panel->arrP, _("Tile"));
  1510.     WMAddPopUpButtonItem(panel->arrP, _("Scale"));
  1511.     WMAddPopUpButtonItem(panel->arrP, _("Center"));
  1512.     WMAddPopUpButtonItem(panel->arrP, _("Maximize"));
  1513.     WMSetPopUpButtonSelectedItem(panel->arrP, 0);
  1514.  
  1515.     WMMapSubwidgets(panel->imageF);
  1516.  
  1517.     /****/
  1518.  
  1519.     panel->okB = WMCreateCommandButton(panel->win);
  1520.     WMResizeWidget(panel->okB, 84, 24);
  1521.     WMMoveWidget(panel->okB, 225, 390);
  1522.     WMSetButtonText(panel->okB, _("OK"));
  1523.     WMSetButtonAction(panel->okB, buttonCallback, panel);
  1524.     
  1525.     panel->cancelB = WMCreateCommandButton(panel->win);
  1526.     WMResizeWidget(panel->cancelB, 84, 24);
  1527.     WMMoveWidget(panel->cancelB, 130, 390);
  1528.     WMSetButtonText(panel->cancelB, _("Cancel"));
  1529.     WMSetButtonAction(panel->cancelB, buttonCallback, panel);
  1530.  
  1531.     WMMapWidget(panel->nameF);
  1532.     WMMapWidget(panel->typeP);
  1533.     WMMapWidget(panel->okB);
  1534.     WMMapWidget(panel->cancelB);
  1535.  
  1536.     WMUnmapWidget(panel->arrP);
  1537.  
  1538.     WMRealizeWidget(panel->win);
  1539.  
  1540.     panel->currentType = -1;
  1541.  
  1542.     panel->sectionParts[TYPE_SOLID][0] = panel->defcF;
  1543.  
  1544.     panel->sectionParts[TYPE_GRADIENT][0] = panel->defcF;
  1545.     panel->sectionParts[TYPE_GRADIENT][1] = panel->gcolF;
  1546.     panel->sectionParts[TYPE_GRADIENT][2] = panel->dirF;
  1547.  
  1548.     panel->sectionParts[TYPE_SGRADIENT][0] = panel->tcolF;
  1549.     panel->sectionParts[TYPE_SGRADIENT][1] = panel->dirF;
  1550.  
  1551.     panel->sectionParts[TYPE_TGRADIENT][0] = panel->tcolF;
  1552.     panel->sectionParts[TYPE_TGRADIENT][1] = panel->dirF;
  1553.     panel->sectionParts[TYPE_TGRADIENT][2] = panel->imageF;
  1554.     panel->sectionParts[TYPE_TGRADIENT][3] = panel->topaF;
  1555.     panel->sectionParts[TYPE_TGRADIENT][4] = panel->arrP;
  1556.  
  1557.     panel->sectionParts[TYPE_PIXMAP][0] = panel->defcF;
  1558.     panel->sectionParts[TYPE_PIXMAP][1] = panel->imageF;
  1559.     panel->sectionParts[TYPE_PIXMAP][2] = panel->arrP;
  1560.  
  1561.  
  1562.     /* setup for first time */
  1563.  
  1564.     changeTypeCallback(panel->typeP, panel);
  1565.  
  1566.     sliderChangeCallback(panel->ghueS, panel);
  1567.     sliderChangeCallback(panel->gsatS, panel);
  1568.  
  1569.     return panel;
  1570. }
  1571.  
  1572.  
  1573.  
  1574. /*
  1575.  *--------------------------------------------------------------------------
  1576.  * Test stuff
  1577.  *--------------------------------------------------------------------------
  1578.  */
  1579.  
  1580. #if 0
  1581.  
  1582. char *ProgName = "test";
  1583.  
  1584. void
  1585. testOKButton(WMWidget *self, void *data)
  1586. {
  1587.     char *test;
  1588.     Display *dpy;
  1589.     Window win;
  1590.     Pixmap pix;
  1591.     RImage *image;
  1592.     
  1593.     TexturePanel *panel = (TexturePanel*)data;
  1594.     /* test = GetTexturePanelTextureString(panel); */
  1595.     
  1596.     wwarning(test);
  1597.     
  1598.     dpy = WMScreenDisplay(WMWidgetScreen(panel->okB));
  1599.     win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 250, 250,
  1600.                   0, 0, 0);
  1601.     XMapRaised(dpy, win);
  1602.     XFlush(dpy);
  1603.     
  1604.     /* image = RenderTexturePanelTexture(panel, 250, 250); */
  1605.     
  1606.     RConvertImage(WMScreenRContext(WMWidgetScreen(panel->okB)), image, &pix);
  1607.     
  1608.     XCopyArea(dpy, pix, win, (WMScreenRContext(WMWidgetScreen(panel->okB)))->copy_gc, 0, 0, image->width, image->height, 
  1609.           0, 0);
  1610.     
  1611.     free (test);
  1612.     
  1613. }
  1614.  
  1615. void testCancelButton(WMWidget *self, void *data){
  1616.     wwarning("Exiting test....");
  1617.     exit(0);
  1618. }
  1619.  
  1620. void wAbort()
  1621. {
  1622.     exit(1);
  1623. }
  1624.  
  1625. int main(int argc, char **argv)
  1626. {
  1627.     TexturePanel *panel;
  1628.     
  1629.     Display *dpy = XOpenDisplay("");
  1630.     WMScreen *scr;
  1631.     
  1632.     /* char *test; */
  1633.     
  1634.     WMInitializeApplication("Test", &argc, argv);
  1635.     
  1636.     if (!dpy) {
  1637.         wfatal("could not open display");
  1638.         exit(1);
  1639.     }
  1640.     
  1641.     scr = WMCreateSimpleApplicationScreen(dpy);
  1642.  
  1643.     panel = CreateTexturePanel(scr);
  1644.  
  1645.     SetTexturePanelOkAction(panel,(WMAction*)testOKButton,panel);
  1646.     SetTexturePanelCancelAction(panel,(WMAction*)testCancelButton,panel);
  1647.  
  1648.     SetTexturePanelTexture(panel, "pinky",
  1649.                PLGetProplistWithDescription("(mdgradient, pink, red, blue, yellow)"));
  1650.  
  1651.     ShowTexturePanel(panel);
  1652.  
  1653.     WMScreenMainLoop(scr);
  1654.     return 0;
  1655. }
  1656. #endif
  1657.